package com.meilingcloud.activiti.instener;

import com.meilingcloud.activiti.domain.ActWfShift;
import com.meilingcloud.activiti.service.IActWfShiftService;
import com.meilingcloud.common.utils.spring.SpringUtils;
import org.activiti.engine.delegate.DelegateExecution;
import org.activiti.engine.delegate.ExecutionListener;
import org.activiti.engine.delegate.Expression;

public class ShiftEndStateListener implements ExecutionListener {

    // 字段注入
    private Expression state;

    @Override
    public void notify(DelegateExecution execution) {
        ActWfShift actWfShift = new ActWfShift();
        actWfShift.setShiftId(execution.getProcessInstanceBusinessKey());
        actWfShift.setInstanceId(execution.getProcessInstanceId());
        actWfShift.setShiftState(state.getValue(execution).toString());

        SpringUtils.getBean(IActWfShiftService.class).completeShift(actWfShift);
    }

}
